package cn.thoughtworks.school.programCenter.configrations;

import cn.thoughtworks.school.programCenter.resolvers.AuthResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter implements HandlerInterceptor {

    @Bean
    ProgramInterceptor ProgramInterceptor(){
        return new ProgramInterceptor();
    }

    @Bean
    ProgramDesignInterceptor ProgramDesignInterceptor(){
        return new ProgramDesignInterceptor();
    }
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new AuthResolver());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //添加拦截器
        registry.addInterceptor(ProgramInterceptor())
                .addPathPatterns("/**");
        registry.addInterceptor(ProgramDesignInterceptor())
                .addPathPatterns("/**");
        super.addInterceptors(registry);
    }
}
